package com.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dao.mybatis.mapper.DepartmentMapper;
import com.entity.Department;
import com.entity.Pagination;

@Repository
public class DepartmentDaoImp implements DepartmentDao {
	@Resource
	private DepartmentMapper mapper;

	@Override
	public List<Department> getAllDepartments(Pagination pagination,Department department) {
		Map<String, Object>map = new HashMap<String, Object>();
		if(pagination!=null){
			map.put("page", pagination.getCurrentPage());
			map.put("startRow", pagination.getStartRow());
			map.put("pageSize", pagination.getEveryPage());
			
		}
		if(department!=null){
			map.put("departName", department.getDepartName()+"");			
		}
		return mapper.getAllDepartments(map);
	}

	@Override
	public Integer insertDepartment(Department department) {
		return mapper.insert(department);
	}

	@Override
	public Integer deleteDepartment(Department department) {
		return mapper.deleteByPrimaryKey(department.getId());
	}

	@Override
	public Integer updateDepartment(Department department) {
		return mapper.updateByPrimaryKey(department);
	}

	@Override
	public int countAll(Department department) {
		return mapper.countAll(department);
	}

	@Override
	public Department findById(Integer id) {
		return mapper.findById(id);
	}
}
